const axios = require('axios')
const utils = require('../utils')
const config = require('../config')

module.exports = async function (params) {
  const db = utils.db;
  let res = await db.getVal(config.DBKEY)

  var params = Object.assign({
    baseURL: res.domain,
    headers: {
      "X-Auth-Token": res.token
    },
  }, params)

  return axios(params).then(res => {
    return res
  }).catch((e) => {
    // console.log(e)
    return e.response ? e.response.data : {
      status: 401,
      message: 'domain不合法'
    }
  });
}